package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.Notice;
import com.k.demo.entity.RedBag;
import com.k.demo.mapper.RedBagMapper;
import com.k.demo.mapper.RedBagRecordMapper;
import com.k.demo.service.RedBagService;
@Service
public class RedBagServiceImpl implements RedBagService {
	@Autowired
	private RedBagMapper redbagMapper;
	@Autowired
	private RedBagRecordMapper redBagRecordMapper;

	//查询所有红包
	public List<RedBag> getAllBags() {
		
		return redbagMapper.getAllRedBags();
	}

	//根据id查找红包
	public List<RedBag> getRedBagById(Integer red_bag_id) {
		
		return redbagMapper.getRedBagById(red_bag_id);
	}

	//新增红包
	public RedBag addRedBag(RedBag redBag) {
		
		int count = redbagMapper.addRedBag(redBag);
		
		if(count>0) {
			
			return redBag;
		}
		
		return null;
	}

	//根据传入的红包对象动态查询
	public List<RedBag> getByRedBag(RedBag redBag) {
		// TODO Auto-generated method stub
		return redbagMapper.getByRedBag(redBag);
	}

	//所有红包分页显示
	public PageInfo<RedBag> getAllWithPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<RedBag>(redbagMapper.getAllRedBags());
	}

	//动态红包对象查询结果分页显示
	public PageInfo<RedBag> searchResultWithPage(int pageNum, int pageSize, RedBag redBag) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<RedBag>(redbagMapper.getByRedBag(redBag));
	}

	//显示当前用户可领的红包  需要续红包记录进行比较
	public List<RedBag> getAvailableRedBag(int user_id) {
	
		return redbagMapper.getAvailableRedBag(user_id);
	}
	
	//获取成为vip时要发送的红包
	public List<RedBag> getVipRedBags(){
		return redbagMapper.getVipRedBags();
	}
	
	

}
